using System;
using HestiaBackup.Library.ConfigurationManager;
using HestiaBackup.Library.Events;

namespace HestiaBackup.Library.Workers
{
    public static class MainWorker
    {
        public static void Process(string configurationFile)
        {
            Settings settings;

            if (string.IsNullOrEmpty(configurationFile))
            {
                throw new ArgumentNullException("configurationFile");
            }

            settings = new Settings(configurationFile);

            FtpChildWorker.OnTransferError += new EventHandler<ChildWorkerErrorEventArgs>(FtpChildWorker_OnTransferError);
            FtpChildWorker.OnFileDownloaded += new EventHandler<FileDownloadedEventArgs>(FtpChildWorker_OnFileDownloaded);
            FtpChildWorker.OnFileAlreadyUpToDate += new EventHandler<FileDownloadedEventArgs>(FtpChildWorker_OnFileAlreadyUpToDate);
            FtpChildWorker.Process(0, settings);
        }

        private static void FtpChildWorker_OnFileAlreadyUpToDate(object sender, FileDownloadedEventArgs e)
        {
            Console.WriteLine("File is already up to date :");
            Console.WriteLine("File name : " + e.fileInfo.FullName);
        }

        private static void FtpChildWorker_OnFileDownloaded(object sender, FileDownloadedEventArgs e)
        {
            Console.WriteLine("File successfully downloaded :");
            Console.WriteLine("File name : " + e.fileInfo.FullName);
            Console.WriteLine("File size : " + e.fileInfo.Length);
        }

        private static void FtpChildWorker_OnTransferError(object sender, ChildWorkerErrorEventArgs e)
        {
            Console.WriteLine(e.Message);
        }
    }
}